package com.ys.service.sys.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ys.entity.sys.YsButtonItem;
import com.ys.mapper.sys.YsButtonItemMapper;
import com.ys.service.sys.YsButtonItemService;
import com.ys.vo.R;

@Service("ysButtonItemService")
public class YsButtonItemServiceImpl implements YsButtonItemService {

	@Autowired
	private YsButtonItemMapper ysButtonItemMapper;

	@Override
	@Transactional
	public R deleteTrue(Long id) {
		if (id == null) {
			return R.error("ID不能为空");
		}
		
		ysButtonItemMapper.deleteTrue(id);
		
		return R.ok();
	}

	@Override
	public R add(Long pid,
			Integer sortNo,
			String event,
			String name,
			String icon) {
		
		YsButtonItem entity = YsButtonItem.ysButtonItem(pid, name, event, icon, sortNo, 1);
		
		ysButtonItemMapper.insert(entity);
		
		return R.ok();
	}

	@Override
	public R edit(Long id,
			String name,
			String event,
			String icon) {
		
		YsButtonItem entity = new YsButtonItem().setId(id).queryFirst();
		entity
			.setName(name)
			.setEvent(event)
			.setIcon(icon);
		
		ysButtonItemMapper.update(entity);
		
		return R.ok();
	}
}
